<%@page import="accessor.DepartmentAccessor"%>
<%@page import="accessor.Department"%>
<%@page import="accessor.UserAccessor"%>
<%@page import="accessor.User"%>
<%@page import="java.util.List"%>
<%@include file="header.jsp" %>
<%@include file="menubar/adminmenu.jsp" %>
<div class="break_line"></div>
<div class="break_line"></div>
<div id="content">
    <div id="title_content">UPDATE USER</div>
    <form method="POST" action="../update_user">
        <%
            UserAccessor userAccessor = new UserAccessor();
            DepartmentAccessor departmentAccessor = new DepartmentAccessor();
            int userID = request.getParameter("userID") != null ? Integer.parseInt(request.getParameter("userID")) : 0;
            User user = userAccessor.getUserByID(userID);
            
            List<Department> departments = departmentAccessor.getAll();
        %>
        <% if (request.getSession().getAttribute("updateError") != null) {%>
                    <div class="form_error">
                        <% out.println(request.getSession().getAttribute("updateError"));%>
                    </div>
                    <%}%>
        <input type="hidden" name="userID" value="<%= user != null ? user.getUserID() : ""%>"/>
        <table class="form_content" width="100%">
            <tr>
                <td>FIRST NAME: </td>
                <td>
                    <% if (request.getSession().getAttribute("update_firstname") != null) {%>
                    <div class="form_error">
                        <% out.println(request.getSession().getAttribute("update_firstname"));%>
                    </div>
                    <%}%>
                    <input type="text" name="first_name" class="form_input" value="<%= user != null ? user.getFirstName() : ""%>"/></td>
            </tr>
            <tr>
                <td>LAST NAME: </td>
                <td>
                    <% if (request.getSession().getAttribute("update_lastname") != null) {%>
                    <div class="form_error">
                        <% out.println(request.getSession().getAttribute("update_lastname"));%>
                    </div>
                    <%}%>
                    <input type="text" name="last_name" class="form_input" value="<%= user != null ? user.getLastName() : ""%>"/>
                </td>
            </tr>
            <tr>
                <td>DEPARTMENT NAME: </td>
                <td>
                    <select name="departmentID" id="departmentID" >
                        <%
                            for (int i = 0; i < departments.size(); i++) {
                                Department d = (Department) departments.get(i);
                        %>
                        <option 
                            <%if(user.getDepartmentID()==d.getDepartmentID()){ out.print("selected='true'");}%> 
                            value="<%=d.getDepartmentID()%>"><%=d.getDepartmentName()%></option>
                        <%}%>
                    </select>
                </td>
            </tr>
            <tr>
                <td>DATE OF BIRTH: </td>
                <td><input type="text" id="date" name="dateOfBirth" class="form_input" value="2011-01-01"/></td>
            </tr>
            <tr>
                <td></td>
                <td colspan="2"><input type="submit" name="submit" class="form_input" style="width: 100px;" value="Update"/></td>
            </tr>
        </table>
    </form>
</div>
<!--END content-->
<%@include file="footer.jsp" %>